<script lang="ts" setup>
import {ref} from "vue";
import {Login} from "../../service/login.ts";
import {userInfoStore} from "../../store";
import {ElMessage} from "element-plus";
import router from "../../router";

const userInfo = userInfoStore()
const pass = ref(true);
const passType = ref("password")
const showPass = () => {
  pass.value = !pass.value;
  if (!pass.value) {
    passType.value = "text"
  } else {
    passType.value = "password"
  }
}

const loginDTO = ref({
  email: "",
  password: "",
  username: "",
})

const login = async () => {
  const data: any = await Login(loginDTO.value);
  if (data.code == 200) {
    console.log(data)
    userInfo.setToken(data.data)
    await router.push({
      path: "/admin/home/user"
    })
  } else {
    ElMessage.error(data.message);
  }
}

</script>
<template>
  <link rel="stylesheet" href="../../assets/icon/iconfont.css">
  <div class="form-box">
    <div class="form-title">
      登陆
    </div>
    <div class="form-content">
      <ul>
        <li id="input-item">
          <span>账号:</span>
          <input type="text" v-model="loginDTO.username">
        </li>
        <li id="input-item">
          <span>密码:</span>
          <input :type="passType" v-model="loginDTO.password">
          <i v-if="pass" @click="showPass" class="iconfont icon-yanjing_yincang_o test"></i>
          <i v-else @click="showPass" class="iconfont icon-yanjing_xianshi_o test"></i>
        </li>
        <li id="input-item"></li>
        <li id="input-item">
          <button type="button" class="form-button" @click="login">登陆</button>
        </li>
      </ul>


    </div>
    <div class="form-footer">

    </div>
  </div>
</template>


<style scoped>
.form-box {
  border: black 1px solid;
  height: 500px;
  min-width: 500px;
  background: hsla(0, 0%, 100%, 0.3);
}

.form-box::before {
  filter: blur(20px);
}

.form-title {
  font-size: 3rem;
  top: 5px;
  margin: auto;
  padding: 5px;
  display: flex;
  justify-content: center;
}

.form-content {
  display: flex;
  flex-direction: column;
  margin: 30px 0;

  ul {
    list-style: none;
  }

  #input-item {
    min-height: 50px;
    padding: 10px;
    margin: 15px 0;
  }

  #input-item > input {
    width: 60%;
    height: 30px;
    outline: none;
    font-size: 1.5rem;
    border: none;
    border-bottom: black 2px solid;
    background: transparent;
    transition: border-color 0.3s;
    padding-right: 10%;
  }

  #input-item > span {
    margin: 0 20px;
    font-size: 30px;
  }

  .form-button {
    display: block;
    width: 30%;
    height: 50px;
    margin: auto;
    font-size: 1.5rem;
    background: black;
    border-radius: 15px;
    color: white;
  }

  .test {
    position: relative;
    left: -32px;
    z-index: 10;
  }

}
</style>